package com.envper.framework.config;

import com.envper.common.util.SnowflakeUtils;
import com.envper.common.util.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class IdConfiguration {
    @Value("${safety.snowflake.epoch}")
    private long twepoch;
    @Value("${safety.snowflake.workerId}")
    private long workerId;
    @Value("${safety.snowflake.dataCenterId}")
    private long dataCenterId;

    @Bean
    public SnowflakeUtils snowflakeUtils(IdUtils idUtils) {
        SnowflakeUtils snowflakeUtils = new SnowflakeUtils(twepoch, workerId, dataCenterId);
        idUtils.setSnowflakeUtils(snowflakeUtils);
        log.info("Initializing snowflakeUtils Success");
        return snowflakeUtils;
    }

}
